package com.mk.web.threadpool.queue;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TimeUnit;

/**
 * Created by WangChen on 2018/12/16 12:55.
 */
public class QueueTest {

    public static void main(String [] args){
        Queue<String> queue = new ArrayBlockingQueue<>(3);
//        queue.element();// throws an exception if this queue is empty
        queue.peek();// null
//        queue.remove();// throws an exception if this queue is empty.
        queue.poll();// null
        queue.offer("a1");
        queue.offer("b1");
        queue.offer("c1");// true
        queue.offer("d1");//false, 注意这里并没有阻塞
        System.out.println(queue.size());// 3
        while (queue.size() > 0){
            String element = queue.element();
            System.out.println("element:" + element);
            String remove = queue.remove();
            System.out.println("remove:" + remove);// a1  b1  c1
        }
        System.out.println(queue.size());// 0
        queue.add("a");
        queue.add("b");
        queue.add("c");// true
//        queue.add("d");// throwing an IllegalStateException if this queue is full
        System.out.println(queue.size());// 3




    }
}
